<?php

namespace app\admin\model;

use think\Model;


class PrizeDraw extends Model
{

    

    

    // 表名
    protected $name = 'prize_draw';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
        'opentime_text'
    ];
    

    



    public function getOpentimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['opentime']) ? $data['opentime'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }

    protected function setOpentimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }

    public function goods(){
        return $this->belongsTo('Goods', 'goods_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }

    public function prize(){
        return $this->belongsTo('Prize', 'prize_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }

    public function user(){
        return $this->belongsTo('User', 'user_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }

    public function order(){
        return $this->belongsTo('Order', 'order_sn', 'order_sn', [], 'LEFT')->setEagerlyType(0);
    }

}
